﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Antlr4;
using Newtonsoft.Json;

namespace DSL
{
    class Program
    {
        static void Main(string[] args)
        {
            var content = File.ReadAllText("test.dsl");

            PrintTokenInfo(content);

        }

        private static void PrintTokenInfo(string content)
        {
            var inputStream = new AntlrInputStream(content);
            var dslLexer = new DSLLexer(inputStream);
            var commonToeknStream = new CommonTokenStream(dslLexer);
            var dslParser = new DSLParser(commonToeknStream);
           
            ParseTreeWalker walker  = new ParseTreeWalker();
            var listener = new DSLListener();
            walker.Walk(listener, dslParser.file());

            var data = LitJson.JsonMapper.ToJson(listener.statementDatas);
            Console.WriteLine(data);
            WriteFile(data);
            var obj = LitJson.JsonMapper.ToObject<List<StatementData>>(data);

            var bytes = File.ReadAllText(path);
            var list  = LitJson.JsonMapper.ToObject<List<StatementData>>(bytes);
               Console.ReadKey();

        }
        static string path = "skill.bytes";

        private static void WriteFile(string content)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

           ;
           using (var stream = File.CreateText(path))
            {
                var arr = content.ToCharArray();
                stream.Write(arr,0, arr.Length);
            }
        }
    }
}
